#ifndef _epwm_c
#define _epwm_c

// Period is 320 counts = 50KHz
// 320/4 = 80

#define PR2_INIT	80

#if FOSC == 4000000
#define T2CON_INIT	0b00000100		// Timer ON, 1:1
#elif FOSC == 16000000
#define T2CON_INIT	0b00000101		// Timer ON, 1:4
#else
#error epwm.c: There is no value for T2CON at the specified clock speed
#endif 

void epwm_config( void )
{
   CCP1CON = 0b00001100;
   T2CON = T2CON_INIT;
   TMR2 = 0;
   PR2 = PR2_INIT;
   epwm_set( 0, 0 );
}

void epwm_set( char pulseLength, char steering )
{
   DC1B0 = pulseLength.0;
   DC1B1 = pulseLength.1;
   CCPR1L = pulseLength >> 2;
   PSTRCON = steering;
}


#endif
